package com.youfang.sixthmedia.message.chat;

import java.util.LinkedList;
import java.util.List;

import org.json.JSONArray;
import org.json.JSONObject;

import com.youfang.sixthmedia.message.model.Buddy;
import com.youfang.sixthmedia.net.MessageDelegate;
import com.youfang.sixthmedia.net.Pair;
import com.youfang.sixthmedia.net.Request;
import com.youfang.sixthmedia.net.Response;

public class GetUnReadMsgHistoryBuddyDelegate extends MessageDelegate {

	public static class Req extends Request {

		@Override
		public List<Pair> getParams() {

			return Pair.p("controller", "message")
					.p("action", "GetUnReadMsgHistoryBuddy").get();
		}

		@Override
		public void genMetaData() {

		}

	}

	public static class Resp extends Response {

		private List<Buddy> dataList = new LinkedList<Buddy>();

		@Override
		protected void decodeBody(JSONObject bodyJSON) throws Exception {
			JSONArray arr = bodyJSON.getJSONArray("data");
			for (int i = 0; i < arr.length(); i++) {
				JSONObject o = arr.getJSONObject(i);
				Buddy buddy = new Buddy();

				// we only need two fields to show the message status icon
				buddy.unreadcount = o.getInt("unreadcount");
				buddy.userid = o.getInt("userid");
				buddy.showMessageCnt = true;
				dataList.add(buddy);

			}

		}

		public List<Buddy> getDataList() {
			return dataList;
		}

		public void setDataList(List<Buddy> dataList) {
			this.dataList = dataList;
		}

	}

	public Req req = new Req();
	public Resp resp = new Resp();

	@Override
	public Request request() {
		return req;
	}

	@Override
	public Response response() {
		return resp;
	}
}
